package com.thunbu.thunbu_meeting_system.activity

import com.cathu.lib_commonkt.base.BaseMVVMActivity
import com.hjq.toast.ToastUtils
import com.thunbu.lib_common.utils.DeviceUtil
import com.thunbu.thunbu_meeting_system.MainActivity
import com.thunbu.thunbu_meeting_system.databinding.ActivityAuthorizationBinding
import com.thunbu.thunbu_meeting_system.gotoActivity
import com.thunbu.thunbu_meeting_system.utils.AppUtils
import com.thunbu.thunbu_meeting_system.viewMdel.AuthorizationViewModel

class AuthorizationActivity:BaseMVVMActivity<ActivityAuthorizationBinding,AuthorizationViewModel>() {
    override fun onMVVMCreated() {
        //首次先绑定设备唯一标识和生成授权码
        if(!AppUtils.isBinded()){
            vm.doBind()
        }
        initView()
        vm.mResult.observe(this){
            AppUtils.setAuthResult(true)
            gotoActivity<LoginActivity> {  }
            finish()
        }
    }

    private fun initView() {
        bindViews.tvDeviceId.text = DeviceUtil.getDeviceId()
        bindViews.tvSubmit.setOnClickListener {
            val code = bindViews.etInput.text.toString()
            if(code.isEmpty()){
                ToastUtils.show("请输入授权码")
                return@setOnClickListener
            }
            vm.doauth(code)
        }
    }
}